def load_text(file_name):
    with open(file_name, "r", encoding="utf-8") as file:
        content = file.read()
    return content

def replace_chars(input_text, cn_text, jp_text):
    replaced_text = []
    for char in input_text:
        if char in cn_text:
            char_index = cn_text.index(char)
            jp_char = jp_text[char_index]
            replaced_text.append(jp_char)
        else:
            replaced_text.append(char)
    return ''.join(replaced_text)

def main():
    cn_file = "cn*.txt"  # 替换成你的cn*.txt文件名
    jp_file = "jp.txt"   # 替换成你的jp.txt文件名

    cn_text = load_text(cn_file)
    jp_text = load_text(jp_file)

    input_text = input("请输入文本: ")
    replaced_text = replace_chars(input_text, cn_text, jp_text)

    print("转换后的文本:")
    print(replaced_text)

if __name__ == "__main__":
    main()

